
//+---------------------------------------------------
//|	301重定向
//+---------------------------------------------------

//定位用户来源
SetMemberSource();

//+---------------------------------------------------
//|	快速定位用户来源
//+---------------------------------------------------
function SetMemberSource(){
	var _str=document.location.href;
	var _substr=getCookie('Source');
	if(!_substr){
		//var _str='/Index/Index/SPGOOGWMVV0006VVVV0000WZ/w/gclid/CJ7lt7muvqYCFUqApAod5ghxHA/index.php';
		if(_str.indexOf('/SP')!=-1 && _str.indexOf('WZ')!=-1){
			_substr = _str.substring(_str.indexOf('/SP')+1,_str.indexOf('WZ')+2);
			setCookie('Source',_substr);
		}
		if(_str.indexOf('/cat/')!=-1 ){
			_substr = _str.substring(_str.indexOf('/cat/')+1);
			setCookie('Source',_substr.replace("/","-"));
		}
		if(_str.indexOf('/Invit/i/u/')!=-1 ){
			_substr = 'Invited';
			setCookie('Source',_substr);
		}
	}
	//alert(_substr);
}

//+---------------------------------------------------
//|	快速方法获得当前的对象
//+---------------------------------------------------
function $byid(objectId){
	return reobj=(typeof(objectId)=="object") ? objectId : document.getElementById(objectId);
}

//+---------------------------------------------------
//|	复制到剪贴板
//+---------------------------------------------------
function copy_code()
{

	var mb_id;
	mb_id=getCookie('mb_id');
	if(!mb_id){
		return;
	}
	addDialogbox("#copy_code","开始复制链接，发送给您的好友吧",10001,502);
	//quitScreenMask();
	interhtml=
	"<div class='paragraph clearfix'>"
	+"<ul class='disc inside'>"
	+"<li>必须通以下链接推荐才有效，不然不知道是谁推荐的哦。</li>"
	+"<li>有一人多号规则，<a target='_blank' href='"+Per_host+APP+"/Article/index/id/16' title='查看什么是一人多号？'>查看详情</a>。</li>"
	+"<li>通过非正常渠道邀请不予承认，请注意。</li>"
	+"<li class='notice'>复制成功后会关闭这个对话框，然后ctrl+v粘贴给好友。</li>"
	+"</ul>"
	+"</div>"

	+"<div class='paragraph clearfix'>"
	+"<h4 class='fl tr' style='width:35px;'>MSN:</h4>"
	+"<input class='input fl' style='width:350px;' value='"+Per_host+APP+"/Index/invite/u/"+mb_id+"' id='link_copy_m' />"
	+"<input class='sendReq fl' type='button' value='复制' />"
	+"<div class='payswf' style='position:absolute; right:0;'>"
	+"<embed name='clipboardswf0' class='clipboardswf' id='clipboardswf0' onmouseover='setcopy_gettext0()' devicefont='false' src='/website/Tpl/default/Public/swf/_clipboard.swf' menu='false' allowscriptaccess='sameDomain' swliveconnect='true' wmode='transparent' type='application/x-shockwave-flash' height='20' width='85'>"
	+"</div>"
	+"</div>"

	+"<div class='paragraph clearfix'>"
	+"<h4 class='fl tr' style='width:35px;'>QQ:</h4>"
	+"<input class='input fl' style='width:350px;' value='"+Per_host+APP+"/Index/invite/u/"+mb_id+"' id='link_copy_q' />"
	+"<input class='sendReq fl' type='button' value='复制' />"
	+"<div class='payswf' style='position:absolute; right:0;'>"
	+"<embed name='clipboardswf1' class='clipboardswf' id='clipboardswf1' onmouseover='setcopy_gettext1()' devicefont='false' src='/website/Tpl/default/Public/swf/_clipboard.swf' menu='false' allowscriptaccess='sameDomain' swliveconnect='true' wmode='transparent' type='application/x-shockwave-flash' height='20' width='85'>"
	+"</div>"
	+"</div>"
	$("#copy_code .dialogboxContent").prepend(interhtml);

}
var clipboardswfdata;
var setcopy_gettext0 = function(){
	clipboardswfdata = $("#link_copy_m").attr("value");
	window.document.clipboardswf0.SetVariable('str', clipboardswfdata);
}
var setcopy_gettext1 = function(){
	clipboardswfdata = $("#link_copy_q").attr("value");
	window.document.clipboardswf1.SetVariable('str', clipboardswfdata);
}
var floatwin = function(){
	// alert('copy success, ' + clipboardswfdata);
	removeDialogbox("#copy_code");
}


//+---------------------------------------------------
//|	显示或隐藏一个对象
//+---------------------------------------------------
function display(objectId){

	if($byid(objectId).style.display=='none'){
		$byid(objectId).style.display='block';
	}else{
		$byid(objectId).style.display='none';
	}
}

//+---------------------------------------------------
//|	JS对list数据的排序
//|	AjaxSortBy (模型,操作,字段,排序,对象,分页)
//AjaxPageBy (model,action,field,sort,obj,page
//+---------------------------------------------------
function AjaxPageBy (url,obj,page){
	ThinkAjax.get(APP+"/"+model+"/"+action+"/","p="+page+"&_order="+field+"&_sort="+sort,obj);
}


//+---------------------------------------------------
//|	测试
//+---------------------------------------------------
function imiajax (){
	$.ajax({
		url: '/js/ajax.js.php',
		type:"GET",
		success: function(msg){}
	});
}


//+---------------------------------------------------
//|	最简单的ajax方式
//|	AjaxSortBy (模型/操作,对象)
//+---------------------------------------------------
function simajax (url,obj){
	//$("#"+obj).html(loading);
	$.ajax({
		//url: APP+"/"+url,
		url: url,
		type:"POST",
		success: function(msg){
			$("#"+obj).html(msg);
		}
	});
}

//+---------------------------------------------------
//|	最简单的ajax方式
//|	AjaxSortBy (模型/操作,对象),会员中心专用
//+---------------------------------------------------
function mbsimajax(passurl,obj){
	window.inibidjs='';//主要处理了会员中心里ajax后不能移除用户正在进行拍卖的进程
	$(document.body).prepend('<div id="highlightTips" style="position:absolute; top:50%; left:50%; margin-left:-100px; width:200px;Z-index:10005;">'+loading+'</div>');
	$.ajax({
		type: "POST",
		url:passurl,
		success: function(msg){
			setTimeout(function(){$("#highlightTips").remove();},1000);
			$("#"+obj).html(msg);
			initStyle();
		}
	});

}

//+---------------------------------------------------
//|	打开模式窗口
//+---------------------------------------------------
function openwindow(theURL)
{
	//window.open(theURL,null,null);
	window.open (theURL, "newwindow", "height=420, width=600, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
}

//+---------------------------------------------------
//|	js时间整除
//+---------------------------------------------------
function Div(exp1, exp2) {
	var n1 = Math.round(exp1); //四舍五入
	var n2 = Math.round(exp2); //四舍五入
	var rslt = n1 / n2; //除
	if (rslt >= 0) {
		rslt = Math.floor(rslt); //返回小于等于原rslt的最大整数。
	}else{
		rslt = Math.ceil(rslt); //返回大于等于原rslt的最小整数。
	}
	return rslt;
}

//+---------------------------------------------------
//|	js时间求余
//+---------------------------------------------------
function Mod(exp1, exp2) {
	var n1 = Math.round(exp1); //四舍五入
	var n2 = Math.round(exp2); //四舍五入
	var rslt = n1 % n2; //除
	if (rslt >= 0) {
		rslt = Math.floor(rslt); //返回小于等于原rslt的最大整数。
	}else{
		rslt = Math.ceil(rslt); //返回大于等于原rslt的最小整数。
	}
	return rslt;
}

//+---------------------------------------------------
//|	js时间求余
//+---------------------------------------------------
function Ft(d) {
	if(d<10){
		d="0"+d
	}
	return d;
}
//+---------------------------------------------------
//|	小数点取两位
//+---------------------------------------------------
function Ftmath(d) {
	numObj = new Number(d);
	d=numObj.toFixed(2);
	return d;
}




//+---------------------------------------------------
//清除URL里面的元素，主要是因为如果有很多个#的锚点没办法定位
//url为输入和地址,ps符号
//+---------------------------------------------------
function clearurl(url,ps){
	var   s=url;
	var   sarray=new   Array();
	sarray=s.split(ps);
	var   sa=sarray[0];
	// alert(sa);
	return sa;

}

function fleshVerify(id){
	//重载验证码
	var timenow = new Date().getTime();
	$byid(id).src= APP+'/User/verify/'+timenow;
	//$byid('verifyImg').src= URL+'/verify/'+timenow;
}

function gotourl(url){
	location.href=APP+url;
}

/*连续字符自动换行*/
function toBreakWord(strContent,intLen){

	var strTemp="";
	while(strContent.length>intLen){
		strTemp+=strContent.substr(0,intLen)+" ";
		strContent=strContent.substr(intLen,strContent.length);
	}
	strTemp+=" "+strContent;
	return strTemp;
}



//+---------------------------------------------------
//|	操作cookie的方法
//@Author: johnson
//+---------------------------------------------------
function setCookie(name,value) {
	var Days = 30; //此 cookie 将被保存 30 天
	var exp  = new Date();    //new Date("December 31, 9998");
	exp.setTime(exp.getTime() + Days*24*60*60*1000);

	//document.cookie = name + "="+value+ ";path=/;expires=" + exp.toGMTString();
	document.cookie = name + "="+ escape (value) + ";path=/;expires=" + exp.toGMTString();

}

function getCookie(name) {
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null){
		if (unescape(arr[2]) == null){
			return ;
		}else{
			return unescape(arr[2]);
		}

	}else{
		return ;
	}
}

function delCookie(name){
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval=getCookie(name);
	if(cval!=null) document.cookie= name + "="+cval+";path=/;expires="+exp.toGMTString();
}

/*以json的形式写入数组cookie*/
function setjsonCookie(name,value){
	//alert(name);
	//alert(value);
	var co = json_encode(value);
	setCookie(name,co);
}

/*以json的形式读取数组cookie*/
function getjsonCookie(name){
	var co = getCookie(name);
	//由于没有用到,把前面的json.js的文件删除
	//alert(json_decode(co));
	if(co!=null){
		co = co.replace(/,_/g, ',');
		co = co.replace(/{_/g, '{');
		co = co.replace(/_}/g, '}');
		return json_decode(co);
	}else{
		return false;
	}

}

/*以删除所有cookie*/
function clearCookie()
{
	var strCookie=document.cookie;
	var arrCookie=strCookie.split("; "); // 将多cookie切割为多个名/值对
	for(var i=0;i <arrCookie.length;i++)
	{ // 遍历cookie数组，处理每个cookie对
		var arr=arrCookie[i].split("=");
		if(arr.length>0)
		delCookie(arr[0]);
	}
}




/*
* @JavaScript Library: jquery.1.3.2.js by John Resig
* @Author: A.D.JC
*
* What are you looking for?
*
*/

/* ----------------------------------------------------------------------------------------------------
* 公共方法
* ----------------------------------------------------------------------------------------------------
*/
/* 公共用来显示ajax的方法 ajaxnote(内容,目标对象id,类型)*/
function showtips(str,target,type)
{
	$('#'+target).html(loading);
	if(type==0)
	{
		//正常
		$('#'+target).html(str);
	}
	else if(type==1)
	{
		//高亮提示
		$('#'+target).html('<div id="highlightTips"><p><img src="'+IMG_PATH+'/sprites/sprite.gif" class="sprite sprite_highlightTips"/>'+str+'</p></div>');
	}
	else if(type==2)
	{
		//警告提示
		$('#'+target).html('<div id="errorTips"><p><img src="'+IMG_PATH+'/sprites/sprite.gif" class="sprite sprite_highlightTips"/>'+str+'</p></div>');
	}
	else if(type==3)
	{
		//成功提示
		$('#'+target).html('<div id="errorTips"><p><img src="'+IMG_PATH+'/sprites/sprite.gif" class="sprite sprite_highlightTips"/>'+str+'</p></div>');
	}
	setTimeout("closetips('"+target+"')", 5000);//清空提示信息
}

/*清空信息的的方法,以后再做一些特效吧*/
function closetips(target)
{
	$('#'+target).html('');
}

function closetips2(target)
{
	$('#'+target).fadeOut("fast");
}


/* ----------------------------------------------------------------------------------------------------
* 公共函数
* ----------------------------------------------------------------------------------------------------
*/

/* check browser version (document.compatMode == "CSS1Compat") */
var sys = {};
var navua = navigator.userAgent.toLowerCase();
var browser;
(browser = navua.match(/msie ([\d.]+)/)) ? sys.ie = browser[1] :
(browser = navua.match(/firefox\/([\d.]+)/)) ? sys.firefox = browser[1] :
(browser = navua.match(/chrome\/([\d.]+)/)) ? sys.chrome = browser[1] :
(browser = navua.match(/opera.([\d.]+)/)) ? sys.opera = browser[1] :
(browser = navua.match(/version\/([\d.]+).*safari/)) ? sys.safari = browser[1] : 0;


/* 限定区域 */
function checkLimits(box,prison)
{
	//获取box对象的偏移
	var box_top    = parseInt(box.css("top"));
	var box_right  = box_left + parseInt(box.css("width"));
	var box_bottom = box_top + parseInt(box.css("height"));
	var box_left   = parseInt(box.css("left"));

	//获取对象的限定区域
	var prison_left   = document.getElementById(prison).offsetLeft;
	var prison_right  = prison_left + document.getElementById(prison).offsetWidth;
	var prison_top    = document.getElementById(prison).offsetTop;
	var prison_bottom = prison_top + document.getElementById(prison).offsetHeight;

	if(box_left < prison_left){box.css("left", prison_left);}
	if(box_top < prison_top){box.css("top", prison_top);}
	if(box_right > prison_right){box.css("left", prison_right - parseInt(box.css("width")));}
	if(box_bottom > prison_bottom){box.css("top", prison_bottom - parseInt(box.css("height")));}
}

/* iframe高度自适应 */
function iframeAutoHeight(obj)
{
	var frm = $byid(obj);
	var subWeb = document.frames ? document.frames[obj].document : frm.contentDocument;
	if (frm != null && subWeb != null){frm.height = subWeb.body.scrollHeight;}
}

/* 最小高度 */
function minHeight(id,obj)
{
	if($(id).height() <  $(obj).height())
	{
		autoHeight(id,obj);
	}
}

/* 高度自适应 */
function autoHeight(id,obj)
{
	$(id).height($(obj).height());
}

/* 宽度自适应 */
function autoWidth(id,obj)
{
	$(id).width($(obj).width());
}

/* 高宽自适应 */
function autoResize(id,obj)
{
	$(id).width($(obj).width());
	$(id).height($(obj).height());
}

/* 浮动层垂直居中的宽度计算，左偏移取自身宽一半的负值 */
function marginLeftOffset(obj)
{
	var leftOffset = -($(obj).width()/2);
	$(obj).css({"margin-left":leftOffset});
}



/* 屏幕遮罩 quitScreenMask()设置了单击或按esc退出遮罩 */
function addScreenMask()
{
	var screenMaskA = '<div id="screenMask" style=" position:absolute; z-index:10000; top:0; left:0; display:none; width:100%; background:#000; opacity:0.5;"></div>';
	var screenMaskB = '<iframe frameborder="0" scrolling="no" id="screenMask" style=" position:absolute; z-index:10000; top:0; left:0; display:none; width:100%; background:#000; filter:alpha(opacity=30);"></iframe>';
	var screenMask = (!sys.ie) ? screenMaskA : screenMaskB;

	$(document.body).prepend(screenMask);
	$("#screenMask").height($(document).height()).fadeIn("fast");
}

function removeScreenMask()
{
	$("#screenMask").fadeOut("fast",function(){
		$(this).remove();
	});
}

function quitScreenMask(fadeOutObj)
{
	$("#screenMask").bind("click", function(){
		removeScreenMask();
		$(fadeOutObj).fadeOut("fast");
		removeDialogbox();//临时加入
	});
	$(document.body).keydown(function(e){
		if (e.keyCode == 27)
		{
			removeScreenMask();
			$(fadeOutObj).fadeOut("fast");
			removeDialogbox();//临时加入
		}
	});
}


/* 对话框 内容嵌入到 .dialogboxContent */
function addDialogbox(objId,title,zIndex,objWidth)
{
	addScreenMask();

	var objIdInHTML = objId.replace(/#/,"");
	var sTop = (document.compatMode == "CSS1Compat") ? document.documentElement.scrollTop : document.body.scrollTop;

	//why document.body.scrollTop == 0 on chrome?
	if (sys.chrome){sTop = document.body.scrollTop;}

	var docBodyScrollTop = sTop + $(window).height()/7;
	var left = $(window).width()/2 - objWidth/2;

	$(document.body).prepend(
	'<div id='+objIdInHTML+' class="dialogbox skin" style="top:'+docBodyScrollTop+'px; left:'+left+'px; z-index:'+zIndex+'; width:'+objWidth+'px;">'+

	'<div class="dialogboxTitle clearfix">'+
	'<h2>'+title+'</h2>'+
	'<p><a class="closeDialogbox" href="javascript:void(0);" title="关闭对话框"><img class="sprite sprite_close" src="'+IMG_PATH+'/sprites/sprite.gif" alt="关闭对话框" /></a></p>'+
	'</div>'+

	'<div class="dialogboxContent"></div>'+
	'</div>'
	);

	$(objId).fadeIn("fast");

	$(objId+" .closeDialogbox").bind("click",function(){
		removeDialogbox(objId);
	});
}

function removeDialogbox(objId)
{
	$(objId).fadeOut("fast",function(){
		removeScreenMask();
		$(this).remove();
		$("html").removeClass("hidden");
	});
}



/* ----------------------------------------------------------------------------------------------------
* 全局函数
* ----------------------------------------------------------------------------------------------------
*/

/* 垂直向上 循环滚动显示
function autoScroll(obj,marginTopValue)
{
$(obj).find("ul:first").animate({
marginTop:marginTopValue
},500,function(){
$(this).css({marginTop:"0"}).find("li:first").appendTo(this);
});
}
function startAutoScroll(obj,time)
{
autoScrollIntervalId = setInterval(obj,time);
}
function clearAutoScroll()
{
clearInterval(autoScrollIntervalId);
}
*/


/* Tabview and Button */
function initStyle()
{
	//tabview
	var $tabs = $(".tab a");

	$tabs.bind("click", function(){
		var tabId = $(this).attr("href");
		var tabIdStr = tabId.split("#");
		var currentTabId = '#'+tabIdStr[1];
		$(currentTabId).show().siblings(".content").hide();
		$(this).parent("li").addClass("on").siblings().removeClass("on");
		$(this).parent("h2").parent("li").addClass("on").siblings().removeClass("on");
		return false;
	})
	.focus(function(){
		$(this).blur();
	});

	//input[type='text'] input[type='password'] textarea button
	$(".input").hover(
	function(){
		$(this).addClass("input-hover");
	},
	function(){
		$(this).removeClass("input-hover");
	});

	$(".input").bind("focus",function(){
		$(this).addClass("input-focus");
	}).blur(function(){
		$(this).removeClass("input-focus");
	});

	$(".textarea").hover(
	function(){
		$(this).addClass("textarea-hover");
	},
	function(){
		$(this).removeClass("textarea-hover");
	});

	$(".textarea").bind("focus",function(){
		$(this).addClass("textarea-focus");
	}).blur(function(){
		$(this).removeClass("textarea-focus");
	});

	$(".button button").bind("click",function(){
		$(this).blur();
	});

	$(".input:disabled").addClass("input-disabled");

	$(".button").hover(
	function(){
		$(this).addClass("button-hover");
	},
	function(){
		$(this).removeClass("button-hover");
	});

	$(".button-hilite").hover(
	function(){
		$(this).addClass("button-hilite-hover");
	},
	function(){
		$(this).removeClass("button-hilite-hover");
	});
}



/* 登录 注册 忘记账户或密码 */
function register()
{
	$("#userEmail").click(function(){
		$("#verifycodeInput").removeClass("displayNone");
	});
}



//jt mouseover & mouseout
function showTip(id){
	$("#"+id).mouseover(function(){
		var self = $(this).attr("id");
		jt(self);
		var _jtc = $(this).attr("jtContent");
		$("#jtContent").html(_jtc);
	}).mouseout(function(){
		$("#jt").remove();
	});
}



/*
* Javascript Tips(jt)
*
* 作用：仅处理获取父级私有属性值后并赋予自身。
*
* 提示：
* 1. 需要以一个事件来触发jt()
* 2. 以id作为唯一标示传给jt()
* 3. 必需加的属性 jtTitle="" jtWidth=""，当需要ajax某个页面的时候，可选属性 jtURL=""(该属性有待修改)
* 4. #jt 是插入层的id，别冲突了

* BidTip Example:

$(document).ready(function(){
$(".jtMO").mouseover(function(){
var self = $(this).attr("id");
jt(self);
}).mouseout(function(){
$("#jt").remove();
});
});

<a id="ajaxTip2" href="/" jtURL='__APP__/User/getcount/' jtTitle="客服中心" jtWidth="250" class="jtMO">JT提示</a>

<span jtTitle="提示" jtWidth="350" id="ajaxTip3" class="button jtBid">
<span class="first-child">
<button type="button" class="strong">出 价</button>
</span>
</span>

*/
function jt(objId)
{
	var de = document.documentElement;
	var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var hasArea = w - getAbsoluteLeft(objId);
	var clickElementy = getAbsoluteTop(objId) - 3;
     
	var $self = $("#" + objId);
	var _u = $self.attr("jtURL");
	var _t = $self.attr("jtTitle");
	var _w = $self.attr("jtWidth");
	var _c = $self.attr("jtContent");
	var jtArray = {"url":_u,"title":_t,"width":_w,"content":_c};

	//
	var _url = jtArray.url;
	if(_url === undefined)
	{
		_url = "";
	}
	else
	{
		$.ajax({
			type: "POST",
			url:_url,
			dataType: "html",
			success: function(msg){
				$("#jtContent").html(msg);
			}
		});
	}

	//
	var _content = jtArray.content;
	if(_content === undefined){_c = "";}

	if(hasArea>((jtArray.width*1)+75))
	{
		$("body").append("<div id='jt' style='display:none; width:"+jtArray.width*1+"px'><div id='jtArrowL'></div><div id='jtTitleL'>"+jtArray.title+"</div><div id='jtContent'><div id='jtLoader'><div></div></div>");
		var arrowOffset = getElementWidth(objId) + 11;
		var clickElementx = getAbsoluteLeft(objId) + arrowOffset;
	}
	else
	{
		$("body").append("<div id='jt' style='display:none; width:"+jtArray.width*1+"px'><div id='jtArrowR' style='left:"+((jtArray.width*1)+1)+"px'></div><div id='jtTitleR'>"+jtArray.title+"</div><div id='jtContent'><div id='jtLoader'><div></div></div>");
		var clickElementx = getAbsoluteLeft(objId) - ((jtArray.width*1) + 15);
	}

	$('#jt').css({left:clickElementx+"px", top:clickElementy+"px"}).fadeIn("fast");

	//Get width
	function getElementWidth(objId)
	{
		var x = $byid(objId);
		return x.offsetWidth;
	}

	//Get left position from the parent object
	function getAbsoluteLeft(objId)
	{
		var o = $byid(objId);
		var oLeft = o.offsetLeft;
		while(o.offsetParent!=null)
		{
			oParent = o.offsetParent;
			oLeft += oParent.offsetLeft;
			o = oParent;
		}
		return oLeft;
	}

	//Get top position from the parent object
	function getAbsoluteTop(objId)
	{
		var o = $byid(objId);
		var oTop = o.offsetTop;
		while(o.offsetParent!=null)
		{
			oParent = o.offsetParent;
			oTop += oParent.offsetTop;
			o = oParent;
		}
		return oTop;
	}
}


/* scaling in proportion */
function drawImage(obj,w,h)
{
	var image = new Image();
	image.src = obj.src;

	if(image.width>0 && image.height>0)
	{
		flag = true;
		if(image.width/image.height >= w/h)
		{
			if(image.width > w)
			{
				obj.width = w;
				obj.height = (image.height*w)/image.width;
			}
			else
			{
				obj.width = image.width;
				obj.height = image.height;
			}
		}
		else
		{
			if(image.height > h)
			{
				obj.height = h;
				obj.width = (image.width*h)/image.height;
			}
			else
			{
				obj.width = image.width;
				obj.height = image.height;
			}
		}
	}
}

